/**
 * 检查基本信息
 * @param oForm
 * @returns {boolean}
 */
function checkJob(oForm) {
    var job_title = str_trim($(oForm).find('#job_title').val());
    if (job_title == '') {
        layerMsg('职位名称名不能为空!', 2);
        $(oForm).find('#job_title').focus();
        $(oForm).find('#job_title').val(job_title);
        return false;
    }
    if ($(oForm).find('#industry').val() == '') {
        layerMsg('请选择所属行业!', 2);
        return false;
    }
    if ($(oForm).find('#job_category1').val() == '') {
        layerMsg('请选择岗位类别!', 2);
        return false;
    }
    if ($(oForm).find('#location1').val() == '') {
        layerMsg('请选择工作地区!', 2);
        return false;
    }
    var recruiting_num = str_trim($(oForm).find('#recruiting_num').val());
    if(recruiting_num == ''){
        layerMsg('请输入招聘人数!',2);
        $(oForm).find('#recruiting_num').focus();
        $(oForm).find('#recruiting_num').val(recruiting_num);
        return false;
    }else{
        var regu =/(^[0-9]+$)/g;
        if (!regu.test(recruiting_num)){
            layerMsg('招聘人数只能为整数!',2);
            $(oForm).find('#recruiting_num').focus();
            $(oForm).find('#recruiting_num').val(recruiting_num);
            return false;
        }
    }
    var salary_above = parseInt($(oForm).find('#salary_above').val());
    var salary_below = parseInt($(oForm).find('#salary_below').val());
    if (salary_above=="" && salary_above.length<1 ){
        layerMsg('请选择开始薪资!', 2);
        return false;
    }else{
        if(salary_below != "" && salary_below.length>0 ){
            if (salary_above > salary_below){
                layerMsg('开始薪资必须大于结束薪资!', 2);
                return false;
            }
        }else if(salary_below=="" || salary_below.length<1){
            layerMsg('请选择结束薪资!', 2);
            return false;
        }
    }
    if ($(oForm).find('#welfare').val() == '') {
        layerMsg('请选择职位诱惑!', 2);
        return false;
    }
    var description = str_trim($(oForm).find('#description').html());
    if (description == '') {
        layerMsg('职位描述不能为空!', 2);
        $(oForm).find('#description').focus();
        $(oForm).find('#description').html(description);
        return false;
    }
    var age_above = $(oForm).find('#age_above').val();
    var age_below = $(oForm).find('#age_below').val();
    if(age_above != "" && age_below != "" ){
        if (age_above > age_below){
            layerMsg('开始年龄必须大于结束年龄!', 2);
            return false;
        }
    }
    if ($(oForm).find('#contact_info').val() == '2') {
        var contacts = str_trim($(oForm).find('#contacts').val());
        if (contacts == '') {
            layerMsg('联系人不能为空!', 2);
            $(oForm).find('#contacts').focus();
            $(oForm).find('#contacts').val(contacts);
            return false;
        }

        var mobile = str_trim($(oForm).find('#mobile').val());
        var phone = str_trim($(oForm).find('#phone').val());
        if( mobile == '' && phone == '' ){
            layerMsg('手机号码和电话号码必须填写一个!',2);
            $(oForm).find('#mobile').focus();
            $(oForm).find('#mobile').val(mobile);
            return false;
        }
        if(phone != ''){
            var regu =/(^[0-9]{2,5}\-[0-9]{7,9})((\-\d{0,10})?)$/g;
            if(!regu.test(phone)){
                layerMsg('请输入正确的电话号码!',2);
                $(oForm).find('#phone').focus();
                $(oForm).find('#phone').val(phone);
                return false;
            }
        }
    }
    $(oForm).find("input[type='submit']").val('保存中...');
    $(oForm).find("input[type='submit']").attr('disabled', true);
    return true;
}

/**
 * 设置职位状态
 * param url
 * param info
 */
function destroy(url,info){
    layer.open({
        title: [
            '加急职位',
            'background-color:#00c6c9; color:#fff;'
        ]
        ,className : 'className' //自定风格
        ,content: info
        ,style: 'font-family:微软雅黑; font-size:.28rem'
        ,shadeClose:false
        ,btn: ['确定', '取消']
        ,yes: function(index){
            $.post(url,{'_token': _token}, function (data) {
                if (data.status == '200') {
                    layerMsg(data.message, 2);
                    location='/mobile/company/jobadmin';
                } else {
                    layerMsg(data.message, 2);
                }
                layer.close(index);
            });
        }
    });
}
/**
 * 设置职位状态
 * param url
 */
function job_status(url){
    var str = '';
    str+='<div class="set_status">';
    str+='<ul>';
    str+='<li><a onclick="set_post(\''+url+'\&status=1\',\'激活\')">激活</a></li>';
    str+='<li><a onclick="set_post(\''+url+'\&status=2\',\'屏蔽\')">屏蔽</a></li>';
    str+='<li><a onclick="set_post(\''+url+'\&status=4\',\'删除\')">删除</a></li>';
    str+='<li><a onclick="layer.closeAll();" >取消</a></li>';
    str+='</ul>';
    str+='</div>';
    layer.open({
        type: 1
        ,content: str
        ,anim: 'up'
        ,style: 'position:fixed; bottom:0; left:0; width: 100%;border:none; '
    });
}
/**
 * 设置职位
 * param url
 * param info
 */
function set_post(url,info){
    layer.closeAll();
    layer.open({
        title: [
            info+'职位',
            'background-color:#00c6c9; color:#fff;'
        ]
        ,className : 'className' //自定风格
        ,content: '您真的要'+info+'这个职位吗？'
        ,style: 'font-family:微软雅黑; font-size:.28rem'
        ,shadeClose:false
        ,btn: ['确定', '取消']
        ,yes: function(index){
            $.post(url,{'_token': _token }, function (data) {
                if (data.status == '200') {
                    layerMsg(data.message, 2);
                    location='/mobile/company/jobadmin';
                } else {
                    layerMsg(data.message, 2);
                }
                layer.close(index);
            });
        }
    });
}
